import mock

def setup_mocked_attribute(self, import_string, *a, **k):
    if 'autospec' not in k:
        k['autospec'] = True
    patcher = mock.patch(import_string, *a, **k)
    attname = import_string.replace('.', '_')
    setattr(self, attname, patcher.start())
    self.addCleanup(patcher.stop)


